﻿using System;
using System.Collections.Generic;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using Librarinth;

using SunwellRenderer.Simulation;

namespace SunwellRenderer.Rendering
{
	public struct ModelMeshData
	{
		public BoundingSphere Bounding;
		public int MaterialIndex;
		public int ModelIndex;
		public int MeshIndex;
		public int OBJIndex;
	}
	public abstract class ShaderEffect : Module<ModelMeshData>
	{
		public abstract void Draw(GraphicsDevice device,int sceneDataIndex,BufferArray<int> meshDatas);

		protected readonly Effect Effect;
		public RenderingModule Parent { get { return SunwellMain.Instance.Renderer; } }
		public ShaderEffect(string assetName)
		{
			Effect	= SunwellMain.Instance.Content.Load<Effect>(assetName);
		}

		protected override void Alloc(ref ModelMeshData data) { }
		protected override void Free(ref ModelMeshData data) { }
	}

	public abstract class ShaderEffect<M> : ShaderEffect
	{
		public M[] MeshDatas { get { return DataPool<M>.Datas; } }

		protected abstract void OnDraw(GraphicsDevice device,int cameraIndex,BufferArray<int> dataIndexes);
		public sealed override void Draw(GraphicsDevice device,int cameraIndex,BufferArray<int> dataIndexes)
		{
			OnDraw(device,cameraIndex,dataIndexes);
		}

		public ShaderEffect(string assetName) : base(assetName) { }
	}
}
